﻿using System;
using Books.Model;

namespace Books.Data.ModelProxies
{
    internal class AuthorProxy : AuthorModel
    {
        public AuthorProxy()
        {
            _books = new Lazy<BookModel[]>(() =>
            {
                using (var db = new BooksContext())
                {
                    return db.GetBooksForAuthor(AuthorId);
                }
            });

            _publishers = new Lazy<PublisherModel[]>(() =>
            {
                using (var db = new BooksContext())
                {
                    return db.GetPublishersForAuthor(AuthorId);
                }
            });
        }

        public override BookModel[] Books
        {
            get { return _books.Value; }
        }

        public override PublisherModel[] Publishers
        {
            get { return _publishers.Value; }
        }

        private Lazy<BookModel[]> _books;
        private Lazy<PublisherModel[]> _publishers;
    }
}
